Steven Ponce home pageSteven Ponce home page Steven Ponce
  • Home
  • Data Visualizations
  • Projects
  • Behind the Viz
  • Resume
  • Email

On this page

  • Challenge
  • Visualization
  • Steps to Create this Graphic
    • 1. Load Packages & Setup
    • 2. Read in the Data
    • 3. Examine the Data
    • 4. Tidy Data
    • 5. Visualization Parameters
    • 6. Plot
    • 7. Save
    • 8. Reproduce

Health financing moved in three directions

  • Show All Code
  • Hide All Code

  • View Source

Each arrow shows how a country’s mix of health funding changed from 2000 to 2023. Moving toward a corner means a larger share from that source. Countries are grouped by the source whose share grew most (darker arrows: that share rose 5 points or more). Private funding lost share in 111 of 148 countries.

SWDchallenge
2026
Between 2000 and 2023, government’s share of health funding grew most in 74 of 148 countries, foreign funding’s in 45 and private funding’s in 29. Ternary arrows trace each country’s mix of government, private and foreign sources, computed from WHO spending in constant US dollars. Built in R with ggplot2, ggtext and showtext.
Author

Steven Ponce

Published

December 1, 2026

Challenge

Most of the charts we make for work are familiar ones: bar charts, line graphs, and tables. But some industries turn to more specialized charts that are commonplace to them and rarely seen elsewhere. This month’s challenge is to borrow one and use it to share a story with data.

Additional information can be found HERE

Visualization

Figure 1: Three ternary plots titled Health financing moved in three directions. Each triangle has corners for government, private, and foreign funding, and each arrow shows one country’s health funding mix moving from 2000 to 2023. Countries are grouped by the source whose share grew most: government in 74 of 148 countries, foreign funding in 45 and private funding in 29. Darker arrows mark gains of 5 percentage points or more. In the government and private panels, most arrows run along or near the bottom edge, where foreign funding is close to zero, while arrows in the foreign-funding panel point up into the triangle. A worked example shows Suriname’s government share rising from 48% to 62%. Private funding lost share in 111 of 148 countries. Data: WHO Global Health Expenditure Database via TidyTuesday.

Key takeaways

  • Countries did not all move toward the same health financing model. Where private funding lost share substantially, government funding was more often the largest gainer than foreign funding.
  • Of the 95 countries where private funding’s share fell by more than 2 percentage points, government funding gained more share in 62 and foreign funding in 33.
  • Across the 175 countries with 2023 data, foreign funding made up 11.0% of the average country’s health financing mix but just 0.3% of their combined health spending. The chart gives each country equal weight, regardless of how much it spends on health.

Steps to Create this Graphic

1. Load Packages & Setup

Show code
```{r}
#| label: load

if (!require("pacman")) install.packages("pacman")
pacman::p_load(
  tidyverse, ggtext, showtext, janitor, scales, glue, ggview
  )

# Source utility functions
suppressMessages(source(here::here("R/utils/fonts.R")))
source(here::here("R/utils/social_icons.R"))
source(here::here("R/utils/image_utils.R"))
source(here::here("R/themes/base_theme.R"))

### |- figure settings ----
fig_w    <- 13
fig_h    <- 6
fig_dpi  <- 320

### |- fonts ----
setup_fonts()
fonts <- get_font_families()
title_family <- fonts$title_1
title_size   <- 30
```

2. Read in the Data

Show code
```{r}
#| label: read

## Every field as character, no NA tokens (a literal "NA" can be a real code).
tt_url <- "https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-04-21/"
health_raw <- read_csv(paste0(tt_url, "health_spending.csv"),
  col_types = cols(.default = col_character()), na = character(), show_col_types = FALSE
)
```

3. Examine the Data

Show code
```{r}
#| label: examine
#| include: true
#| eval: true
#| results: 'hide'
#| warning: false

glimpse(health_raw)
health_raw |> count(indicator_code)
```

4. Tidy Data

Show code
```{r}
#| label: tidy
#| output: false

### |- shares from constant-2023 US$, 2000 and 2023 ----
shares <- health_raw |>
  filter(
    indicator_code %in% c("gghed_usd2023", "pvtd_usd2023", "ext_usd2023"),
    year %in% c("2000", "2023"), value != "NA"
  ) |>
  mutate(value = as.numeric(value)) |>
  select(iso3_code, country_name, year, indicator_code, value) |>
  pivot_wider(names_from = indicator_code, values_from = value) |>
  drop_na() |>
  mutate(
    total = gghed_usd2023 + pvtd_usd2023 + ext_usd2023,
    gov = gghed_usd2023 / total, pvt = pvtd_usd2023 / total, ext = ext_usd2023 / total
  ) |>
  filter(total > 0) |>
  select(iso3_code, country_name, year, gov, pvt, ext)

### |- one row per country: 2000 -> 2023 ----
moves <- shares |>
  pivot_wider(names_from = year, values_from = c(gov, pvt, ext)) |>
  drop_na() |>
  mutate(
    d_gov = gov_2023 - gov_2000, d_pvt = pvt_2023 - pvt_2000, d_ext = ext_2023 - ext_2000,
    gain_max = pmax(d_gov, d_pvt, d_ext),
    grew = case_when(
      d_gov == gain_max ~ "gov",
      d_ext == gain_max ~ "ext",
      TRUE              ~ "pvt"
    ),
    clear = gain_max >= 0.05,
    # ternary -> plane: government (0, 0), private (1, 0), foreign (0.5, sqrt(3)/2)
    x0 = pvt_2000 + ext_2000 / 2, y0 = ext_2000 * sqrt(3) / 2,
    x1 = pvt_2023 + ext_2023 / 2, y1 = ext_2023 * sqrt(3) / 2
  )

### |- numbers for the copy (all from the data) ----
n_countries <- nrow(moves)
n_grew      <- count(moves, grew) |> deframe()
n_clear     <- sum(moves$clear)
n_small     <- n_countries - n_clear
n_pvt_fell  <- sum(moves$d_pvt < 0)

### |- panel headings ----
panel_lab <- c(
  gov = glue("Government's share grew most<br><span style='font-size:11pt'>{n_grew['gov']} countries</span>"),
  ext = glue("Foreign funding's share grew most<br><span style='font-size:11pt'>{n_grew['ext']} countries</span>"),
  pvt = glue("Private share grew most<br><span style='font-size:11pt'>{n_grew['pvt']} countries</span>")
)
moves <- moves |> mutate(panel = factor(panel_lab[grew], levels = panel_lab))

### |- worked example: one real arrow, chosen by a rule declared before rendering ----
## Rule (2026-12-01): government panel; clear movers (government share +5 pts or more) whose
## foreign share is >= 5% at both ends (off the bottom edge); pick the arrow whose length is
## nearest the median length of ALL arrows in the government panel.
gov_panel <- moves |> filter(grew == "gov") |> mutate(len = sqrt((x1 - x0)^2 + (y1 - y0)^2))
example <- gov_panel |>
  filter(d_gov >= 0.05, ext_2000 >= 0.05, ext_2023 >= 0.05) |>
  slice_min(abs(len - median(gov_panel$len)), n = 1, with_ties = FALSE)
## label block in the empty upper-left of the panel, one leader to the arrow's midpoint;
## short year tags at tail (2000) and head (2023)
example_note <- tibble(
  panel = factor(panel_lab["gov"], levels = panel_lab),
  x = 0.215, y = 0.60,                # outside the left edge: no arrow passes here
  label = glue("{example$country_name}\ndot = 2000\narrowhead = 2023\ngovernment\n{percent(example$gov_2000, 1)} \u2192 {percent(example$gov_2023, 1)}"),
  lead_x = 0.20, lead_y = 0.37,
  mid_x = (example$x0 + example$x1) / 2, mid_y = (example$y0 + example$y1) / 2
)
example_tags <- tibble(
  panel = factor(panel_lab["gov"], levels = panel_lab),
  x = c(example$x0 + 0.015, example$x1 - 0.012),
  y = c(example$y0 + 0.012, example$y1 + 0.03),
  hjust = c(0, 1), label = c("2000", "2023")
)
edge_label <- tibble(
  panel = factor(panel_lab["gov"], levels = panel_lab),
  x = 0.5, y = -0.075, label = "Bottom edge: 0% foreign funding"
)

### |- triangle scaffold (repeats in every panel) ----
h <- sqrt(3) / 2
tri <- tibble(x = c(0, 1, 0.5, 0), y = c(0, 0, h, 0))
grid_lines <- map_dfr(c(0.25, 0.5, 0.75), \(s) bind_rows(
  tibble(set = "ext", x = c(s / 2, 1 - s / 2), y = s * h),              # foreign share = s
  tibble(set = "pvt", x = c(s, 0.5 + s / 2), y = c(0, (1 - s) * h)),    # private share = s
  tibble(set = "gov", x = c(1 - s, 0.5 - s / 2), y = c(0, (1 - s) * h)) # government share = s
) |> mutate(level = s))
corners <- tibble(                       # centred under / over each vertex: no clash with the next panel
  x = c(0, 1, 0.5), y = c(-0.075, -0.075, h + 0.05),
  label = c("Government", "Private", "Foreign"), hjust = 0.5
)
```

5. Visualization Parameters

Show code
```{r}
#| label: params

### |- plot aesthetics ----
clrs <- get_theme_colors(
  palette = list(
    accent = "#722F37",  
    muted  = "#B9B1A7",   
    frame  = "#8C847C",
    grid   = "#E4DFD6"
  )
)
col_ink    <- clrs$title
col_label  <- clrs$label
col_second <- clrs$caption
col_accent <- clrs$palette$accent
col_muted  <- clrs$palette$muted
col_frame  <- clrs$palette$frame
col_grid   <- clrs$palette$grid

### |- titles and caption ----
title_text <- "Health financing moved in three directions"

subtitle_text <- glue(
  "Each arrow shows how a country's mix of health funding changed from 2000 to 2023. ",
  "Moving toward a corner means a larger share from that source. ",
  "Countries are grouped by the source whose share grew most ",
  "(<span style='color:{col_accent}'>**darker arrows**</span>: that share rose 5 points or more). ",
  "Private funding lost share in {n_pvt_fell} of {n_countries} countries."
)

caption_note <- glue(
  "Shares of current health expenditure, not amounts. {n_countries} countries with data for 2000 and 2023. ",
  "Private: households, employers and non-profits, including out-of-pocket payments. ",
  "Foreign: all funding from outside the country. Arrows are straight lines between 2000 and 2023; the years between are not drawn."
)

caption_text <- paste0(
  caption_note, "<br>",
  create_swd_caption(
    year = 2026,
    month = "Dec",
    source_text = "WHO Global Health Expenditure Database via TidyTuesday"
  )
)

### |- plot theme ----
base_theme <- create_base_theme(clrs)  

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    plot.title = element_text(
      face = "bold", family = title_family, size = title_size,
      color = col_ink, margin = margin(b = 8)
    ),
    plot.subtitle = element_textbox_simple(
      family = fonts$subtitle, size = 11.5, color = col_second,
      lineheight = 1.3, margin = margin(b = 18)
    ),
    plot.caption = element_textbox_simple(
      family = fonts$caption, size = 7, color = col_second,
      lineheight = 1.35, margin = margin(t = 14)
    ),
    strip.text = element_textbox_simple(
      family = fonts$text, face = "bold", size = 13, color = col_ink,
      halign = 0.5, lineheight = 1.2, margin = margin(b = 14)
    ),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    panel.grid = element_blank(),
    panel.spacing = unit(5, "lines"),
    plot.margin = margin(16, 30, 10, 30)   
  )
)

theme_set(weekly_theme)
```

6. Plot

Show code
```{r}
#| label: plot
#| output: false

### |- main plot ----
arrow_head <- arrow(length = unit(0.055, "in"), type = "closed")

p <- ggplot() +
  # Geoms
  geom_line(data = grid_lines, aes(x, y, group = interaction(set, level)), color = col_grid, linewidth = 0.3) +
  geom_path(data = tri, aes(x, y), color = col_frame, linewidth = 0.45) +
  geom_segment(
    data = filter(moves, !clear), aes(x0, y0, xend = x1, yend = y1),
    color = col_muted, linewidth = 0.3, arrow = arrow_head
  ) +
  geom_segment(
    data = filter(moves, clear), aes(x0, y0, xend = x1, yend = y1),
    color = col_accent, linewidth = 0.4, arrow = arrow_head
  ) +
  geom_segment(                     # casing: background-coloured underlay isolates the example arrow
    data = mutate(example, panel = factor(panel_lab["gov"], levels = panel_lab)),
    aes(x0, y0, xend = x1, yend = y1), color = clrs$background, linewidth = 2.4,
    arrow = arrow(length = unit(0.09, "in"), type = "closed")
  ) +
  geom_segment(
    data = mutate(example, panel = factor(panel_lab["gov"], levels = panel_lab)),
    aes(x0, y0, xend = x1, yend = y1), color = col_ink, linewidth = 0.7, arrow = arrow_head
  ) +
  # Annotate
  geom_segment(
    data = example_note, aes(lead_x, lead_y, xend = mid_x, yend = mid_y),
    color = col_ink, linewidth = 0.3
  ) +
  geom_text(
    data = example_note, aes(x, y, label = label),
    family = fonts$text, size = 3.1, color = col_ink, lineheight = 0.95, hjust = 1, vjust = 1
  ) +
  geom_point(                       # the example's 2000 position (the only start dot on the chart)
    data = mutate(example, panel = factor(panel_lab["gov"], levels = panel_lab)),
    aes(x0, y0), color = col_ink, fill = clrs$background, shape = 21, size = 2.2, stroke = 0.7
  ) +
  geom_text(
    data = edge_label, aes(x, y, label = label),
    family = fonts$text, size = 3.1, color = col_label, fontface = "italic"
  ) +
  geom_text(
    data = corners, aes(x, y, label = label, hjust = hjust),
    family = fonts$text, size = 3.6, color = col_label
  ) +
  # Scales
  coord_equal(xlim = c(-0.02, 1.02), ylim = c(-0.02, h + 0.02), clip = "off") +
  facet_wrap(~panel, nrow = 1) +
  # Labs
  labs(title = title_text, subtitle = subtitle_text, caption = caption_text)
```

7. Save

Show code
```{r}
#| label: save
#| warning: false

### |- save ----
main_path  <- here::here("data_visualizations", "SWD Challenge", "2026", "swd_2026_12.png")
thumb_path <- here::here("data_visualizations", "SWD Challenge", "2026", "thumbnails", "swd_2026_12.png")

# Full-size version, for the QMD figure
save_ggplot(
  plot = p,
  file = main_path,
  width = fig_w,
  height = fig_h,
  units = "in",
  dpi = fig_dpi,
  create.dir = TRUE
)

# Reduced-size thumbnail, for the YAML `image:` field
fs::dir_create(dirname(thumb_path))
magick::image_read(main_path) |>
  magick::image_resize("400") |>
  magick::image_write(thumb_path)
```

8. Reproduce

TipSession info
Show code
```{r}
#| eval: true
#| warning: false

sessionInfo()
```
R version 4.6.1 (2026-06-24)
Platform: aarch64-apple-darwin23
Running under: macOS Tahoe 26.7.3

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.6/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] here_1.0.2      ggview_0.2.2    glue_1.8.1      scales_1.4.0   
 [5] janitor_2.2.1   showtext_0.9-8  showtextdb_3.0  sysfonts_0.8.9 
 [9] ggtext_0.2.0    lubridate_1.9.5 forcats_1.0.1   stringr_1.6.0  
[13] dplyr_1.2.1     purrr_1.2.2     readr_2.2.0     tidyr_1.3.2    
[17] tibble_3.3.1    ggplot2_4.0.3   tidyverse_2.0.0 pacman_0.5.1   

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       xfun_0.60          htmlwidgets_1.6.4  tzdb_0.5.0        
 [5] vctrs_0.7.3        tools_4.6.1        generics_0.1.4     curl_7.1.0        
 [9] parallel_4.6.1     pkgconfig_2.0.3    RColorBrewer_1.1-3 S7_0.2.2          
[13] lifecycle_1.0.5    compiler_4.6.1     farver_2.1.2       textshaping_1.0.5 
[17] snakecase_0.11.1   litedown_0.10      htmltools_0.5.9    yaml_2.3.12       
[21] pillar_1.11.1      crayon_1.5.3       magick_2.9.1       commonmark_2.0.0  
[25] tidyselect_1.2.1   digest_0.6.39      stringi_1.8.7      labeling_0.4.3    
[29] rprojroot_2.1.1    fastmap_1.2.0      grid_4.6.1         cli_3.6.6         
[33] magrittr_2.0.5     utf8_1.2.6         withr_3.0.3        bit64_4.8.2       
[37] timechange_0.4.0   rmarkdown_2.31     bit_4.6.0          otel_0.2.0        
[41] ragg_1.5.2         hms_1.1.4          evaluate_1.0.5     knitr_1.51        
[45] markdown_2.0       rlang_1.3.0        gridtext_0.1.6     Rcpp_1.1.2        
[49] xml2_1.6.0         rstudioapi_0.19.0  vroom_1.7.1        jsonlite_2.0.0    
[53] R6_2.6.1           fs_2.1.0           systemfonts_1.3.2 
TipCode

The complete code for this analysis is in swd_2026_12.qmd. The full site is in the poncest/personal-website repository.

TipReferences

Primary data

  • World Health Organization. Global Health Expenditure Database (GHED). apps.who.int/nha/database

Source used here

  • TidyTuesday 2026, week 16 (2026-04-21): health_spending.csv, curated by Luca Picci (ONE Data) with the bblocks-data-importers package. rfordatascience/tidytuesday

Definitions (WHO)

  • Government: domestic government revenues and social health insurance contributions. GGHE-D
  • Private: households, corporations and non-profits, prepaid or out-of-pocket. PVT-D
  • Foreign: all funding from outside the country, including foreign transfers distributed by government. EXT

Analysis

  • 148 countries with all three sources in both 2000 and 2023. Shares are computed from constant 2023 US$ amounts, where the three sources sum to current health expenditure; WHO’s published percentage fields are rounded and not used.
  • Each country sits in the panel of the source whose share grew most. Darker arrows mark a largest gain of 5 percentage points or more: a design threshold for emphasis, not a significance test.
  • Suriname was chosen as the worked example by a rule fixed before rendering: the government-panel arrow nearest the panel’s median length, among countries off the bottom edge.
  • Every number in the chart and the takeaways is reproduced by the decision record.

Claim limits

  • Shares, not amounts: a rising foreign share can mean more foreign money or less domestic money.
  • Each arrow joins two endpoints; the path between 2000 and 2023 is not shown.
  • Countries count equally: across the 175 countries with 2023 data, foreign funding was 11.0% of the average country’s mix but 0.3% of combined spending.
  • The data describe composition, not causes, and end in 2023.

Challenge

  • Storytelling with Data. DEC 2026: borrow a chart from another industry. community.storytellingwithdata.com
NoteHelper functions

This analysis uses functions from my personal module library. The data tidying and chart logic use standard tidyverse packages.

Functions used:

  • fonts.R: setup_fonts(), get_font_families(): font management with showtext
  • social_icons.R: create_swd_caption(): formatted SWD challenge caption with social handles
  • base_theme.R: create_base_theme(), extend_weekly_theme(), get_theme_colors(): custom ggplot2 themes

Browse the helper functions on GitHub

Back to top

Citation

BibTeX citation:
@online{ponce2026,
  author = {Ponce, Steven},
  title = {Health Financing Moved in Three Directions},
  date = {2026-12-01},
  url = {https://stevenponce.netlify.app/data_visualizations/SWD%20Challenge/2026/swd_2026_12.html},
  langid = {en}
}
For attribution, please cite this work as:
Ponce, Steven. 2026. “Health Financing Moved in Three Directions.” December 1. https://stevenponce.netlify.app/data_visualizations/SWD%20Challenge/2026/swd_2026_12.html.
Source Code
---
title: "Health financing moved in three directions"
subtitle: "Each arrow shows how a country's mix of health funding changed from 2000 to 2023. Moving toward a corner means a larger share from that source. Countries are grouped by the source whose share grew most (darker arrows: that share rose 5 points or more). Private funding lost share in 111 of 148 countries."
description: "Between 2000 and 2023, government's share of health funding grew most in 74 of 148 countries, foreign funding's in 45 and private funding's in 29. Ternary arrows trace each country's mix of government, private and foreign sources, computed from WHO spending in constant US dollars. Built in R with ggplot2, ggtext and showtext."
date: "2026-12-01"
author:
  - name: "Steven Ponce"
    url: "https://stevenponce.netlify.app"
citation:
  url: "https://stevenponce.netlify.app/data_visualizations/SWD%20Challenge/2026/swd_2026_12.html"
categories: ["SWDchallenge", "2026"]
tags: [
  "SWDchallenge",
  "borrow-a-chart",
  "ternary-plot",
  "small-multiples",
  "arrow-chart",
  "compositional-data",
  "health-financing",
  "global-health",
  "who-ghed",
  "annotation",
  "ggtext",
  "tidytuesday-data",
  "2026"
]
image: "thumbnails/swd_2026_12.png"
format:
  html:
    toc: true
    toc-depth: 4
    code-link: true
    code-fold: true
    code-tools: true
    code-summary: "Show code"
editor_options: 
  chunk_output_type: inline
execute: 
  freeze: true
  cache: false
  error: false
  message: false
  warning: false
  eval: true
---

### Challenge

Most of the charts we make for work are familiar ones: bar charts, line graphs, and tables. But some industries turn to more specialized charts that are commonplace to them and rarely seen elsewhere. This month's challenge is to borrow one and use it to share a story with data.

Additional information can be found [HERE](https://community.storytellingwithdata.com/challenges/dec-2026-borrow-a-chart-from-another-industry)

### Visualization

![Three ternary plots titled Health financing moved in three directions. Each triangle has corners for government, private, and foreign funding, and each arrow shows one country's health funding mix moving from 2000 to 2023. Countries are grouped by the source whose share grew most: government in 74 of 148 countries, foreign funding in 45 and private funding in 29. Darker arrows mark gains of 5 percentage points or more. In the government and private panels, most arrows run along or near the bottom edge, where foreign funding is close to zero, while arrows in the foreign-funding panel point up into the triangle. A worked example shows Suriname's government share rising from 48% to 62%. Private funding lost share in 111 of 148 countries. Data: WHO Global Health Expenditure Database via TidyTuesday.](swd_2026_12.png){#fig-1}

::: {.key-takeaways}
[Key takeaways]{.key-takeaways-label}

- Countries did not all move toward the same health financing model. Where private funding lost share substantially, government funding was more often the largest gainer than foreign funding.
- Of the 95 countries where private funding's share fell by more than 2 percentage points, government funding gained more share in 62 and foreign funding in 33.
- Across the 175 countries with 2023 data, foreign funding made up 11.0% of the average country's health financing mix but just 0.3% of their combined health spending. The chart gives each country equal weight, regardless of how much it spends on health.
:::

### [**Steps to Create this Graphic**]{.mark}

#### [1. Load Packages & Setup]{.smallcaps}

```{r}
#| label: load

if (!require("pacman")) install.packages("pacman")
pacman::p_load(
  tidyverse, ggtext, showtext, janitor, scales, glue, ggview
  )

# Source utility functions
suppressMessages(source(here::here("R/utils/fonts.R")))
source(here::here("R/utils/social_icons.R"))
source(here::here("R/utils/image_utils.R"))
source(here::here("R/themes/base_theme.R"))

### |- figure settings ----
fig_w    <- 13
fig_h    <- 6
fig_dpi  <- 320

### |- fonts ----
setup_fonts()
fonts <- get_font_families()
title_family <- fonts$title_1
title_size   <- 30
```

#### [2. Read in the Data]{.smallcaps}

```{r}
#| label: read

## Every field as character, no NA tokens (a literal "NA" can be a real code).
tt_url <- "https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-04-21/"
health_raw <- read_csv(paste0(tt_url, "health_spending.csv"),
  col_types = cols(.default = col_character()), na = character(), show_col_types = FALSE
)
```

#### [3. Examine the Data]{.smallcaps}

```{r}
#| label: examine
#| include: true
#| eval: true
#| results: 'hide'
#| warning: false

glimpse(health_raw)
health_raw |> count(indicator_code)
```

#### [4. Tidy Data]{.smallcaps}

```{r}
#| label: tidy
#| output: false

### |- shares from constant-2023 US$, 2000 and 2023 ----
shares <- health_raw |>
  filter(
    indicator_code %in% c("gghed_usd2023", "pvtd_usd2023", "ext_usd2023"),
    year %in% c("2000", "2023"), value != "NA"
  ) |>
  mutate(value = as.numeric(value)) |>
  select(iso3_code, country_name, year, indicator_code, value) |>
  pivot_wider(names_from = indicator_code, values_from = value) |>
  drop_na() |>
  mutate(
    total = gghed_usd2023 + pvtd_usd2023 + ext_usd2023,
    gov = gghed_usd2023 / total, pvt = pvtd_usd2023 / total, ext = ext_usd2023 / total
  ) |>
  filter(total > 0) |>
  select(iso3_code, country_name, year, gov, pvt, ext)

### |- one row per country: 2000 -> 2023 ----
moves <- shares |>
  pivot_wider(names_from = year, values_from = c(gov, pvt, ext)) |>
  drop_na() |>
  mutate(
    d_gov = gov_2023 - gov_2000, d_pvt = pvt_2023 - pvt_2000, d_ext = ext_2023 - ext_2000,
    gain_max = pmax(d_gov, d_pvt, d_ext),
    grew = case_when(
      d_gov == gain_max ~ "gov",
      d_ext == gain_max ~ "ext",
      TRUE              ~ "pvt"
    ),
    clear = gain_max >= 0.05,
    # ternary -> plane: government (0, 0), private (1, 0), foreign (0.5, sqrt(3)/2)
    x0 = pvt_2000 + ext_2000 / 2, y0 = ext_2000 * sqrt(3) / 2,
    x1 = pvt_2023 + ext_2023 / 2, y1 = ext_2023 * sqrt(3) / 2
  )

### |- numbers for the copy (all from the data) ----
n_countries <- nrow(moves)
n_grew      <- count(moves, grew) |> deframe()
n_clear     <- sum(moves$clear)
n_small     <- n_countries - n_clear
n_pvt_fell  <- sum(moves$d_pvt < 0)

### |- panel headings ----
panel_lab <- c(
  gov = glue("Government's share grew most<br><span style='font-size:11pt'>{n_grew['gov']} countries</span>"),
  ext = glue("Foreign funding's share grew most<br><span style='font-size:11pt'>{n_grew['ext']} countries</span>"),
  pvt = glue("Private share grew most<br><span style='font-size:11pt'>{n_grew['pvt']} countries</span>")
)
moves <- moves |> mutate(panel = factor(panel_lab[grew], levels = panel_lab))

### |- worked example: one real arrow, chosen by a rule declared before rendering ----
## Rule (2026-12-01): government panel; clear movers (government share +5 pts or more) whose
## foreign share is >= 5% at both ends (off the bottom edge); pick the arrow whose length is
## nearest the median length of ALL arrows in the government panel.
gov_panel <- moves |> filter(grew == "gov") |> mutate(len = sqrt((x1 - x0)^2 + (y1 - y0)^2))
example <- gov_panel |>
  filter(d_gov >= 0.05, ext_2000 >= 0.05, ext_2023 >= 0.05) |>
  slice_min(abs(len - median(gov_panel$len)), n = 1, with_ties = FALSE)
## label block in the empty upper-left of the panel, one leader to the arrow's midpoint;
## short year tags at tail (2000) and head (2023)
example_note <- tibble(
  panel = factor(panel_lab["gov"], levels = panel_lab),
  x = 0.215, y = 0.60,                # outside the left edge: no arrow passes here
  label = glue("{example$country_name}\ndot = 2000\narrowhead = 2023\ngovernment\n{percent(example$gov_2000, 1)} \u2192 {percent(example$gov_2023, 1)}"),
  lead_x = 0.20, lead_y = 0.37,
  mid_x = (example$x0 + example$x1) / 2, mid_y = (example$y0 + example$y1) / 2
)
example_tags <- tibble(
  panel = factor(panel_lab["gov"], levels = panel_lab),
  x = c(example$x0 + 0.015, example$x1 - 0.012),
  y = c(example$y0 + 0.012, example$y1 + 0.03),
  hjust = c(0, 1), label = c("2000", "2023")
)
edge_label <- tibble(
  panel = factor(panel_lab["gov"], levels = panel_lab),
  x = 0.5, y = -0.075, label = "Bottom edge: 0% foreign funding"
)

### |- triangle scaffold (repeats in every panel) ----
h <- sqrt(3) / 2
tri <- tibble(x = c(0, 1, 0.5, 0), y = c(0, 0, h, 0))
grid_lines <- map_dfr(c(0.25, 0.5, 0.75), \(s) bind_rows(
  tibble(set = "ext", x = c(s / 2, 1 - s / 2), y = s * h),              # foreign share = s
  tibble(set = "pvt", x = c(s, 0.5 + s / 2), y = c(0, (1 - s) * h)),    # private share = s
  tibble(set = "gov", x = c(1 - s, 0.5 - s / 2), y = c(0, (1 - s) * h)) # government share = s
) |> mutate(level = s))
corners <- tibble(                       # centred under / over each vertex: no clash with the next panel
  x = c(0, 1, 0.5), y = c(-0.075, -0.075, h + 0.05),
  label = c("Government", "Private", "Foreign"), hjust = 0.5
)
```

#### [5. Visualization Parameters]{.smallcaps}

```{r}
#| label: params

### |- plot aesthetics ----
clrs <- get_theme_colors(
  palette = list(
    accent = "#722F37",  
    muted  = "#B9B1A7",   
    frame  = "#8C847C",
    grid   = "#E4DFD6"
  )
)
col_ink    <- clrs$title
col_label  <- clrs$label
col_second <- clrs$caption
col_accent <- clrs$palette$accent
col_muted  <- clrs$palette$muted
col_frame  <- clrs$palette$frame
col_grid   <- clrs$palette$grid

### |- titles and caption ----
title_text <- "Health financing moved in three directions"

subtitle_text <- glue(
  "Each arrow shows how a country's mix of health funding changed from 2000 to 2023. ",
  "Moving toward a corner means a larger share from that source. ",
  "Countries are grouped by the source whose share grew most ",
  "(<span style='color:{col_accent}'>**darker arrows**</span>: that share rose 5 points or more). ",
  "Private funding lost share in {n_pvt_fell} of {n_countries} countries."
)

caption_note <- glue(
  "Shares of current health expenditure, not amounts. {n_countries} countries with data for 2000 and 2023. ",
  "Private: households, employers and non-profits, including out-of-pocket payments. ",
  "Foreign: all funding from outside the country. Arrows are straight lines between 2000 and 2023; the years between are not drawn."
)

caption_text <- paste0(
  caption_note, "<br>",
  create_swd_caption(
    year = 2026,
    month = "Dec",
    source_text = "WHO Global Health Expenditure Database via TidyTuesday"
  )
)

### |- plot theme ----
base_theme <- create_base_theme(clrs)  

weekly_theme <- extend_weekly_theme(
  base_theme,
  theme(
    plot.title = element_text(
      face = "bold", family = title_family, size = title_size,
      color = col_ink, margin = margin(b = 8)
    ),
    plot.subtitle = element_textbox_simple(
      family = fonts$subtitle, size = 11.5, color = col_second,
      lineheight = 1.3, margin = margin(b = 18)
    ),
    plot.caption = element_textbox_simple(
      family = fonts$caption, size = 7, color = col_second,
      lineheight = 1.35, margin = margin(t = 14)
    ),
    strip.text = element_textbox_simple(
      family = fonts$text, face = "bold", size = 13, color = col_ink,
      halign = 0.5, lineheight = 1.2, margin = margin(b = 14)
    ),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    panel.grid = element_blank(),
    panel.spacing = unit(5, "lines"),
    plot.margin = margin(16, 30, 10, 30)   
  )
)

theme_set(weekly_theme)
```

#### [6. Plot]{.smallcaps}

```{r}
#| label: plot
#| output: false

### |- main plot ----
arrow_head <- arrow(length = unit(0.055, "in"), type = "closed")

p <- ggplot() +
  # Geoms
  geom_line(data = grid_lines, aes(x, y, group = interaction(set, level)), color = col_grid, linewidth = 0.3) +
  geom_path(data = tri, aes(x, y), color = col_frame, linewidth = 0.45) +
  geom_segment(
    data = filter(moves, !clear), aes(x0, y0, xend = x1, yend = y1),
    color = col_muted, linewidth = 0.3, arrow = arrow_head
  ) +
  geom_segment(
    data = filter(moves, clear), aes(x0, y0, xend = x1, yend = y1),
    color = col_accent, linewidth = 0.4, arrow = arrow_head
  ) +
  geom_segment(                     # casing: background-coloured underlay isolates the example arrow
    data = mutate(example, panel = factor(panel_lab["gov"], levels = panel_lab)),
    aes(x0, y0, xend = x1, yend = y1), color = clrs$background, linewidth = 2.4,
    arrow = arrow(length = unit(0.09, "in"), type = "closed")
  ) +
  geom_segment(
    data = mutate(example, panel = factor(panel_lab["gov"], levels = panel_lab)),
    aes(x0, y0, xend = x1, yend = y1), color = col_ink, linewidth = 0.7, arrow = arrow_head
  ) +
  # Annotate
  geom_segment(
    data = example_note, aes(lead_x, lead_y, xend = mid_x, yend = mid_y),
    color = col_ink, linewidth = 0.3
  ) +
  geom_text(
    data = example_note, aes(x, y, label = label),
    family = fonts$text, size = 3.1, color = col_ink, lineheight = 0.95, hjust = 1, vjust = 1
  ) +
  geom_point(                       # the example's 2000 position (the only start dot on the chart)
    data = mutate(example, panel = factor(panel_lab["gov"], levels = panel_lab)),
    aes(x0, y0), color = col_ink, fill = clrs$background, shape = 21, size = 2.2, stroke = 0.7
  ) +
  geom_text(
    data = edge_label, aes(x, y, label = label),
    family = fonts$text, size = 3.1, color = col_label, fontface = "italic"
  ) +
  geom_text(
    data = corners, aes(x, y, label = label, hjust = hjust),
    family = fonts$text, size = 3.6, color = col_label
  ) +
  # Scales
  coord_equal(xlim = c(-0.02, 1.02), ylim = c(-0.02, h + 0.02), clip = "off") +
  facet_wrap(~panel, nrow = 1) +
  # Labs
  labs(title = title_text, subtitle = subtitle_text, caption = caption_text)
```

#### [7. Save]{.smallcaps}

```{r}
#| label: save
#| warning: false

### |- save ----
main_path  <- here::here("data_visualizations", "SWD Challenge", "2026", "swd_2026_12.png")
thumb_path <- here::here("data_visualizations", "SWD Challenge", "2026", "thumbnails", "swd_2026_12.png")

# Full-size version, for the QMD figure
save_ggplot(
  plot = p,
  file = main_path,
  width = fig_w,
  height = fig_h,
  units = "in",
  dpi = fig_dpi,
  create.dir = TRUE
)

# Reduced-size thumbnail, for the YAML `image:` field
fs::dir_create(dirname(thumb_path))
magick::image_read(main_path) |>
  magick::image_resize("400") |>
  magick::image_write(thumb_path)
```


#### [8. Reproduce]{.smallcaps}

::: {.callout-tip collapse="true"}
##### Session info

```{r}
#| eval: true
#| warning: false

sessionInfo()
```
:::

::: {.callout-tip collapse="true"}
##### Code

The complete code for this analysis is in [`swd_2026_12.qmd`](https://github.com/poncest/personal-website/blob/master/data_visualizations/SWD%20Challenge/2026/swd_2026_12.qmd). The full site is in the [poncest/personal-website repository](https://github.com/poncest/personal-website/).
:::

::: {.callout-tip collapse="true"}
##### References

**Primary data**

- World Health Organization. *Global Health Expenditure Database (GHED)*. [apps.who.int/nha/database](https://apps.who.int/nha/database/)

**Source used here**

- TidyTuesday 2026, week 16 (2026-04-21): `health_spending.csv`, curated by Luca Picci (ONE Data) with the `bblocks-data-importers` package. [rfordatascience/tidytuesday](https://github.com/rfordatascience/tidytuesday/tree/main/data/2026/2026-04-21)

**Definitions (WHO)**

- Government: domestic government revenues and social health insurance contributions. [GGHE-D](https://www.who.int/data/gho/data/indicators/indicator-details/GHO/domestic-general-government-health-expenditure-(gche-d)-as-percentage-of-current-health-expenditure)
- Private: households, corporations and non-profits, prepaid or out-of-pocket. [PVT-D](https://www.who.int/data/gho/data/indicators/indicator-details/GHO/domestic-private-health-expenditure-(pvt-d)-as-percentage-of-current-health-expenditure-(che)-(-))
- Foreign: all funding from outside the country, including foreign transfers distributed by government. [EXT](https://www.who.int/data/gho/data/indicators/indicator-details/GHO/external-health-expenditure-(ext)-as-percentage-of-current-health-expenditure-(che)-(-))

**Analysis**

- 148 countries with all three sources in both 2000 and 2023. Shares are computed from constant 2023 US$ amounts, where the three sources sum to current health expenditure; WHO's published percentage fields are rounded and not used.
- Each country sits in the panel of the source whose share grew most. Darker arrows mark a largest gain of 5 percentage points or more: a design threshold for emphasis, not a significance test.
- Suriname was chosen as the worked example by a rule fixed before rendering: the government-panel arrow nearest the panel's median length, among countries off the bottom edge.
- Every number in the chart and the takeaways is reproduced by the [decision record](https://github.com/poncest/SWDchallenge/blob/main/2026/12_Dec/decisions/swd_2026_12_decision_record.R).

**Claim limits**

- Shares, not amounts: a rising foreign share can mean more foreign money or less domestic money.
- Each arrow joins two endpoints; the path between 2000 and 2023 is not shown.
- Countries count equally: across the 175 countries with 2023 data, foreign funding was 11.0% of the average country's mix but 0.3% of combined spending.
- The data describe composition, not causes, and end in 2023.

**Challenge**

- Storytelling with Data. *DEC 2026: borrow a chart from another industry*. [community.storytellingwithdata.com](https://community.storytellingwithdata.com/challenges/dec-2026-borrow-a-chart-from-another-industry)
:::

::: {.callout-note collapse="true"}
##### Helper functions

This analysis uses functions from my personal module library. The data tidying and chart logic use standard tidyverse packages.

**Functions used:**

- **`fonts.R`**: `setup_fonts()`, `get_font_families()`: font management with showtext
- **`social_icons.R`**: `create_swd_caption()`: formatted SWD challenge caption with social handles
- **`base_theme.R`**: `create_base_theme()`, `extend_weekly_theme()`, `get_theme_colors()`: custom ggplot2 themes

[Browse the helper functions on GitHub](https://github.com/poncest/personal-website/tree/master/R)
:::

© 2024–2026 Steven Ponce. Built with R and Quarto.

Source Issues